import os.path
# 模块测试完成


class Myreadfile():
    """
    Myreadfile [summary]
    用来读取官方的.dat文件，并返回二次指派问题(QAP)问题中的N,A,B

    [extended_summary]
    """
    N = 0
    A = []
    B = []

    def __init__(self, filepath):
        """
        __init__ [summary]
        输入.dat文件的路径，如果不存在就报错
        [extended_summary]

        :param filepath: [description]
        :type filepath: [type]
        """
        if not os.path.isfile(filepath):
            print("文件不存在")
        else:
            self.Datfile = open(filepath)
            self.file = self.Datfile.readlines()
            self.get_N()
            self.get_A()
            self.get_B()
            self.Datfile.close()

    def get_N(self):
        """
        get_N 返回N


        [extended_summary]
        """
        self.N = int(self.file[0])

    def get_A(self):
        """
        get_A 返回A

        [extended_summary]
        """
        for i in range(2, 2+self.N):
            temp = self.file[i][:-1].split(" ")
            self.A.append([int(j) for j in temp])

    def get_B(self):
        """
        get_B 返回B

        [extended_summary]
        """
        for i in range(2+self.N+1, 3+2*self.N):
            temp = self.file[i][:-1].split(" ")
            temp = [i for i in temp if i != ""]
            self.B.append([int(j) for j in temp])
